package com.AAL.DAO;

import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IPlanDetailOfWarehouseDAO;
import com.AAL.Model.LogForPlan;
import com.AAL.Model.PlanDetailsOfWareHouse;
import com.AAL.Utils.HibernateUtil;

public class PlanDetailOfWarehouseDAO implements IPlanDetailOfWarehouseDAO {

	@Override
	public PlanDetailsOfWareHouse saveAndUpdatePlanDetailOfWareHouse(
			PlanDetailsOfWareHouse planDetail) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(planDetail);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return planDetail;
	}

	@Override
	public PlanDetailsOfWareHouse deletePlanDetailsOfWareHouse(int planDetailID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			PlanDetailsOfWareHouse planDetailsOfWareHouse = (PlanDetailsOfWareHouse) session
					.load(PlanDetailsOfWareHouse.class, planDetailID);
			if (null != planDetailsOfWareHouse) {
				session.delete(planDetailsOfWareHouse);
			}
			session.getTransaction().commit();
			return planDetailsOfWareHouse;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public PlanDetailsOfWareHouse getDetailsOfWareHouse(int planDetailID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		PlanDetailsOfWareHouse planDetailsOfWareHouse = (PlanDetailsOfWareHouse) session
				.load(PlanDetailsOfWareHouse.class, planDetailID);
		return planDetailsOfWareHouse;
	}

	@Override
	public List<PlanDetailsOfWareHouse> getLstPlanDetailsOfWareHousesByPlanByLogForPlan(
			LogForPlan logForPlan) {
		// TODO Auto-generated method stub
		return null;
	}

}
